<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/tld/pageutil.tld" prefix="pu"%>
<%@taglib uri="/WEB-INF/tld/pageable.tld" prefix="pageable"%>
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt-rt"%>
<%@taglib prefix="yaodian100" uri="/WEB-INF/tld/yaodian100.tld" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<%@page import="com.yaodian100.core.common.utils.ServerValue"%>
<script type="text/javascript" charset="UTF-8" src="<c-rt:url value="/js/yaodian100_mid_soaddr.js"/>"></script>
${pu:reqSet('orderProduct', pu:get('com.yaodian100.ec.order.entity.OrderProduct', pu:toLong(param.orderProdId))) }
${pu:reqSet('order', pu:get('com.yaodian100.ec.order.entity.Orders', orderProduct.orderId)) }
<style>
.tableAlignLeft td{
	text-align:left;
}
</style>
<h1>
换货单(订单编号：${order.orderId })
</h1>
<script>
$(function(){
	$('.productQty').each(function(){
			
			$(this).change(function(){
				id=$(this).attr('id');
				index=id.replace('qty','');
				qty=$(this).attr('value');
				tp6=$(this).hasClass('qtys6');
				//alert($('.prodSpecId'+index+">select").length);
				$(":select[name=prodSpecIds]").each(function(){						
					$(this).attr('disabled', 'disabled');							
				});
				$('.prodSpecId'+index).each(function(){
					$(this).attr('disabled', 'disabled');
					$(this).css('display', 'none');
					
					//$('.prodSpecId'+index+">select").attr('disabled', 'disabled');
				});
				
				$('.prodSpecId'+index).each(function(i){
					//alert(i);
					if(i<qty){
						$(this).css('display', '');
						$(this).attr('disabled', '');
						if(tp6){
							$('.prodSpecId'+index+">select")[i].attr('disabled', '');
						}else{
							$(":select[name=prodSpecIds]").each(function(j){							
								if(i==j){								
									$(this).attr('disabled', '');
								}	
							});
						}
					}
				});
			});
		});
		$('.prodSpecId').each(function(){
			$(this).attr('disabled', 'disabled');
			$(this).css('display', 'none');
		});
		<c-rt:forEach items="${prodMajors}" var="pdjs" varStatus="status">
		<yaodian100:specSelectJsChgProd prodMajors="${prodMajors[status.index]}" prodInvMap="${prodInvMaps[status.index]}"/>
		</c-rt:forEach>
});
function checkForm(){
	var returnCount=0;
	$('.qtys0').each(function(){
		returnCount+=$(this).attr('value');
	});
	$('.qtys1').each(function(){
		returnCount+=$(this).attr('value');
	});
	$('.qtys2').each(function(){
		returnCount+=$(this).attr('value');
	});
	$('.qtys3').each(function(){
		returnCount+=$(this).attr('value');
	});
	$('.qtys4').each(function(){
		returnCount+=$(this).attr('value');
	});
	$('.qtys5').each(function(){
		returnCount+=$(this).attr('value');
	});
	$('.qtys6').each(function(){
		returnCount+=$(this).attr('value');
	});
	$('.qtys7').each(function(){
		returnCount+=$(this).attr('value');
	});
	
	var errorMessage="";
	var error=0;	
	if(returnCount==0){
		errorMessage+='请选择换货商品数数量\r\n';
	}
	$(":input[id*=selectMs_]").each(function(i){
		
		if($(this).attr('disabled')!=true){
			if($(this).attr('value')==''){
				error++;
			}
		}
	});
	if(error>0){
		errorMessage+='请选择换货商品属性\r\n';
	}

	error=0;
	$('.reason').each(function(){
		if($(this).attr('value')==''){
			error++;
		}
	});
	if(error>0){
		errorMessage+="请选择换货原因\r\n";
	}
	error=0;
	
	$('.description').each(function(){
		if($(this).attr('value')==''){
			error++;
		}
	});
	if(error>0){
		errorMessage+="请填写换货原因描述\r\n";
	}
	error=0;

	$('.accessaryDescription').each(function(){
		if($(this).attr('value')==''){
			error++;
		}
	});
	if(error>0){
		errorMessage+="请填写配件赠品状态\r\n";
	}
	if($('#receiverName').attr('value')==''){
		errorMessage+="请填联络人姓名\r\n";
	}
	if($('#province').attr('value')==''
		|| $('#city').attr('value')==''
		|| $('#district').attr('value')==''
		|| $('#receiverAddr').attr('value')==''
		|| $('#receiverZip').attr('value')==''){
		errorMessage+="请填联络地址\r\n";
	}

	if($('#receiverMobile').attr('value')==''){
		if($('#receiverPhoneArea').attr('value')==''
			|| $('#receiverPhone').attr('value')==''
			){
			
			errorMessage+="请填手机电话或固定电话\r\n";
		}else{
			if(
					$('#receiverPhone').attr('value').length<5
					|| $('#receiverPhone').attr('value').length>10
					|| isNaN($('#receiverPhone').attr('value'))
				){
				
				errorMessage+="固定电话为长度5～10的数字\r\n";
			}
		}
		
	}else if(isNaN($('#receiverMobile').attr('value')) || $('#receiverMobile').attr('value').length>11){
		errorMessage+="手机电话为长度小于11的数字\r\n";
	}
	
	//document.returnForm.prodSpecIds.value=document.returnForm.theDetailId.value+"_1_"+document.returnForm.theSpecId.value;
	applySpecIds();
	if(errorMessage!=''){
		alert(errorMessage);
	}
	else{
		document.returnForm.submit();
	}
}
function applySpecIds(){
$(":input[id*=selectSs]").each(function(i){
	id=$(this).attr('id');
	index=id.replace('selectSs','');
	if(window.ActiveXObject){
		$(this).val($('#theDetailId'+index).val()+'_1_'+$('#theSpecId'+index).val());
	}else{
		$(this).attr('value', $('#theDetailId'+index).attr('value')+'_1_'+$('#theSpecId'+index).attr('value'));
		
	}
	});
	
}
</script>

<form name="returnForm" method="post" action="/ecadmin/serviceOrder/changeProduct.do">
<input type="hidden" name="paymentTp" value="${order.paymentTp }"/>
<input type="hidden" name="orderId" id="orderId" value="${order.orderId }"/>
<input type="hidden" name="memberId" value="${order.memberId }"/>
<input type="hidden" name="orderProdId" value="${orderProduct.orderProdId }"/>
<table class="tb-1 tableAlignLeft">
<thead>
<tr>
	<th>orderProdId</th><th>明细</th>
</tr>
</thead>
<tbody>
	
		
		
		
		<tr>
			<td>${orderProduct.orderProdId }<input type="hidden" name="orderProdId" value="${orderProduct.orderProdId }"/></td>
			
			<td>
			<table>
			<c-rt:forEach items="${orderProduct.orderProductDetail}" var="opd" varStatus="status">
			
			<s:set name="orderDetailId">
				${opd.orderDetailId}
			</s:set>
			<s:if test="%{serviceOrderService.isOrderDetailReturnableChangable(#orderDetailId)}">
			<tr>
				<td>
					<table>
						<tr>
							<td>
								<c-rt:if test="${opd.detailTp=='0'}">
								<c-rt:set var="detailTp" scope="request" value="0"/>
								<span class="type-0">主商品</span>
								</c-rt:if>
								<c-rt:if test="${opd.detailTp=='1'}">
								<c-rt:set var="detailTp" scope="request" value="1"/>
								<span class="type-1">预购</span>
								</c-rt:if>
								<c-rt:if test="${opd.detailTp=='2'}">
								<c-rt:set var="detailTp" scope="request" value="2"/>
								<span class="type-2">赠品</span>
								</c-rt:if>
								<c-rt:if test="${opd.detailTp=='3'}">
								<c-rt:set var="detailTp" scope="request" value="3"/>
								<span class="type-3">加购</span>
								</c-rt:if>
								<c-rt:if test="${opd.detailTp=='4'}">
								<c-rt:set var="detailTp" scope="request" value="4"/>
								<span class="type-4">活动</span>
								</c-rt:if>
								<c-rt:if test="${opd.detailTp=='5'}">
								<c-rt:set var="detailTp" scope="request" value="5"/>
								<span class="type-5">满额购</span>
								</c-rt:if>
								<c-rt:if test="${opd.detailTp=='6'}">
								<c-rt:set var="detailTp" scope="request" value="6"/>
								<span class="type-6">任选</span>
								</c-rt:if>
								<c-rt:if test="${opd.detailTp=='7'}">
								<c-rt:set var="detailTp" scope="request" value="7"/>
								<span class="type-7">精品</span>
								</c-rt:if>
								${opd.prodName }[${opd.prodSpecName }]x
								<select name="qtys" id="qty${status.index }" class="qtys${detailTp } productQty">
								<c-rt:forEach begin="0" end="${opd.qty}" varStatus="index">
								<option value="${index.index }">${index.index }</option>
								</c-rt:forEach>
								</select>
								</td>
								<td>
									${pu:reqSet('prod', pu:get('com.yaodian100.ec.product.entity.Product',opd.prodId)) }
									
								${pu:reqSet('paramsProdSpecs', null) }
									${pu:reqSet('parasProdSpecs', null)}
									${pu:listAdd('paramsProdSpecs', opd.prodId)}
									${pu:listAdd('paramsProdSpecs', 'Y')}
									
									${pu:reqSet('hqlProdSpecs', 'from Specification where productId=? and isDelete!=?')}
									${pu:reqSet('prodSpecs', pu:queryByHql(hqlProdSpecs, pu:arrayGet('paramsProdSpecs'), null))}
									
								  <c-rt:forEach begin="1" end="${opd.qty}" step="1" varStatus="qtyI">								  
								
								 <%-- 
								 <select name="prodSpecIds" class="prodSpecId prodSpecId${status.index }" disabled="disabled">
									<option value="">请选择</option>
									<c-rt:forEach items="${prodSpecs}" var="spec">
										<option value="${opd.orderDetailId}_1_${spec.specificationId }"
											<c-rt:if test="${spec.specificationId == opd.prodSpecId}">selected="selected"</c-rt:if>>${spec.specificationName}</option>
									</c-rt:forEach>
								</select> 
								 --%>
								 	<p class="prodSpecId prodSpecId${status.index }">
								 	<c-rt:if test="${empty order.outerOrderId}">
								 	${prod.mainCodeLabel}：    
									<select class="pdtype" id="selectMs_${prod.productId}_${qtyI.index }" name="odId_${opd.orderDetailId}">
									<c-rt:if test="${fn:length(prod.specMajors) > 0}">
									<option value="请选择">请选择</option>
									</c-rt:if>
									<c-rt:forEach items="${prod.specMajors}" var="specObj" varStatus="duo_status">
									<option value="${specObj.mainSpecId}">${specObj.mainSpecName}</option>
									</c-rt:forEach>
									</select>
									<br />
									${prod.secondCodeLabel}：    
									<select class="pdtype" id="selectSs_${prod.productId}_${qtyI.index }" name="prodSpecIds" disabled="disabled"><option  value="">请选择</option></select>
									
									</c-rt:if>
									<c-rt:if test="${!empty order.outerOrderId}">
									<input type="hidden" id="theDetailId_${prod.productId}_${qtyI.index }" name="theDetailId" value="${opd.orderDetailId }"/>
									<input type="hidden" id="selectSs_${prod.productId}_${qtyI.index }" name="prodSpecIds"/>
									

	<c-rt:if test="${empty opd.outerCid}">
	属性代码：<input type="text" name="theSpecId" id="theSpecId_${prod.productId}_${qtyI.index }" size="10" value="${opd.prodSpecId }"/>
	</c-rt:if>				
									
	<%--淘宝功能 --%>
	<c-rt:if test="${!empty opd.outerCid}">
	属性:
	<c-rt:set var="tmall_safeQty" value="${pu:menuOption('SystemValue', 'tmall_safeQty')}" scope="request"/>
	<c-rt:forEach items="${tmallProducts}" var="tmallProd">
		<c-rt:if test="${tmallProd.numIid==opd.outerProdId}">
			<select id="theSpecId_${prod.productId}_${qtyI.index }" name="theSpecId">
				<c-rt:forEach items="${tmallProd.skus}" var="sku">
				${pu:reqSet('outerSpecName', '') }
				<c-rt:forEach items="${pvs[sku.skuId] }" var="pv">
					
					<c-rt:set var="outerSpecName" scope="request">
					${outerSpecName } ${pv.name }
					</c-rt:set>
					</c-rt:forEach>
					<c-rt:if test="${sku.quantity<pu:toLong(tmall_safeQty.memo1)}">
						<c-rt:set var="optionAttr" scope="request">
						disabled="disabled" <c-rt:if test="${pu:toLong(sku.outerId) eq pu:toLong(opd.prodSpecId) }">selected="selected"</c-rt:if>
						</c-rt:set>
					</c-rt:if>
					<c-rt:if test="${sku.quantity>pu:toLong(tmall_safeQty.memo1)}">
					<c-rt:set var="optionAttr" scope="request">
					 <c-rt:if test="${pu:toLong(sku.outerId) eq pu:toLong(opd.prodSpecId) }">selected="selected"</c-rt:if>
					</c-rt:set>
					</c-rt:if>
					<option value="${sku.outerId }" ${optionAttr }>
					${outerSpecName }
					</option>
				</c-rt:forEach>
			</select>
		</c-rt:if>
		
	</c-rt:forEach>
	</c-rt:if>
									
									</c-rt:if>
									</p>
								</c-rt:forEach>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			</s:if>
			</c-rt:forEach>
			</table>
			
			</td>
			
		</tr>
		
		
</tbody>
</table>

<table class="tb-1 tableAlignLeft">
	<tr>
		<th>
		换货原因
		</th>
		<td>
		 <select name="reason" class="reason">
	          <option value="">请选择原因</option>
	          <option value="订购错误">订购错误</option>
	          <option value="商品发错">商品发错</option>
	          <option value="商品或外包装破损">商品或外包装破损</option>
	          <option value="商品不如预期">商品不如预期</option>
	          <option value="商品属性不符">商品属性不符</option>
	          <option value="价格比较贵">价格比较贵</option>
	          <option value="与介绍不符">与介绍不符</option>
	          <option value="改买其他款式">改买其他款式</option>
	          <option value="商品未如期收到">商品未如期收到</option>
	          <option value="不会使用">不会使用</option>
	          <option value="其他">其他</option>
	          </select>
		</td>
	</tr>
	<tr>
		<th>
		换货原因描述
		</th>
		<td>
		<textarea name="description" class="description" rows="5" cols="100"></textarea>
		</td>
	</tr>
	<tr>
		<th>
		配件赠品状态
		</th>
		<td>
		<input class="return-txtfild accessaryDescription" type="text" name="accessaryDescription" value="" size="100"/>
		</td>
	</tr>
	<tr>
		<th>
		姓名
		</th>
		<td>
		<input type="text" name="receiverName" id="receiverName" value="${order.receiverName }" size="10" />
		</td>
	</tr>
	<tr>
		<th>联络地址</th>
		<td>
		<select id="province" name="receiverProvince" class="c-prov"><option value="">== 选择省 ==</option>
			<option value="陕西">陕西</option>
			<c-rt:forEach items="${provincesMap}" var="province" >
				<option value="${province.key}">${province.key}</option>
			</c-rt:forEach>		
		</select> 
              市：<select name="receiverCity" id="city"> 
                <option value="">== 选择城市 ==</option>
                <option value="安康市">安康市</option>
              </select> 
              区：<select name="receiverArea" id="district"> 
                <option value="">== 选择地区 ==</option>
                <option value="汉滨区">汉滨区</option>
              </select> 
              <br /> 
              邮编：<input type="text" name="receiverZip" id="receiverZip" value="${order.receiverZip}"/>
              街道：<input size="50" name="receiverAddr" id="receiverAddr" value="${order.receiverAddr }" /> 
		</td>
	</tr>
	<tr>
		<th>手机电话</th>
		<td><input type="text" name="receiverMobile" id="receiverMobile" value="${order.receiverMobile }" size="10" /></td>
	</tr>
	<tr>
		<th>固定电话</th>
		<td>
			<input type="text" name="receiverPhoneArea" id="receiverPhoneArea" value="${order.receiverPhoneArea }" size="3" />-<input type="text" name="receiverPhone" id="receiverPhone" value="${order.receiverPhone }" size="7" />-分机<input type="text" name="receiverExt" id="receiverExt" value="${order.receiverExt }" size="4" />
		</td>
	</tr>
	<tr>
		<th></th>
		<td>
		<input type="button" value="送出" onclick="checkForm()"/>
		<input type="hidden" value="${order.receiverProvince}" id="receiverProvince"/>
		<input type="hidden" value="${order.receiverCity}" id="receiverCity"/>
		<input type="hidden" value="${order.receiverArea}" id="receiverArea"/>		
		<s:hidden name="oldServiceId" />
		<s:hidden name="orderProdId" />
		<input type="reset" value="重置"/>
		</td>
	</tr>
</table>
</form>